<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        // event loop 轮询机制
        // 构造函数同步执行 1 2 输出，单线程继续 4 输出，resolve() event loop 3输出 
        const promise = new Promise((resolve, reject) => {
            // PromiseState - pending
            console.log(1)
            resolve('success')//resolve(值)传给.then(这里) PromiseState-fulfilled
            console.log(2)
        })
        // setTimeout 也要进 event loop 是宏任务
        setTimeout(() => {
            console.log(5)
        }, 0)
        // .then 进 event loop 是 微任务 更紧急
        promise.then(() => {
            console.log(3)
        })
        console.log(4)
    </script>
</body>

</html>